{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ecb430b8-bce2-4323-a1a1-46dfa460bedc",
   "metadata": {},
   "source": [
    "<center><img src=\"./image/CLBLOGO.jpg\" alt=\"创乐博\" style=\"width: 300px;\"/></center>\n",
    "\n",
    "# 39.VL53L0X ToF激光雷达距离传感器实验\n",
    "\n",
    "@－－－－湖南创乐博智能科技有限公司－－－－<br>\n",
    "@  文件名：39.VL53L0X ToF激光雷达距离传感器.py <br>\n",
    "@  版本：V2.0 <br>\n",
    "@  author: zhulin<br>\n",
    "@  说明：VL53L0X ToF激光雷达距离传感器\n",
    "VL53L0X ToF激光雷达距离传感器，通过第三方自定义的adafruit_vl53l0x库操作该传感器模块，该传感器模块采用的是I2C的通讯方式，可以打印出测量的距离值！！！<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "445be920-d473-45b8-8aa6-e4b55af36b2e",
   "metadata": {},
   "source": [
    "## 1.导入必要的库文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9d214c4-40b8-454d-b76f-33676b68fb1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import board\n",
    "import busio\n",
    "import adafruit_vl53l0x"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbee25d9-eeff-4358-8858-030d6724a8f1",
   "metadata": {},
   "source": [
    "## 2.实例化I2C设备和初始化激光测距传感器模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8061dfaa-9d83-4472-90c2-1fc60451907a",
   "metadata": {},
   "outputs": [],
   "source": [
    "pii2c = busio.I2C(board.SCL, board.SDA)\n",
    "makerobo_vl53 = adafruit_vl53l0x.VL53L0X(pii2c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39cd4d39-7284-48c4-920c-59969df8900a",
   "metadata": {},
   "source": [
    "## 3.主程序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a89b2dfd-31a9-4982-9059-42b33115b115",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 程序入口\n",
    "if __name__ == '__main__':\n",
    "    try:\n",
    "        # 循环持续输出距离值\n",
    "        while True:\n",
    "            print(\"Range: {0}mm\".format(makerobo_vl53.range))   # 打印出距离值\n",
    "            time.sleep(1.0)                                     # 延时1s\n",
    "    except KeyboardInterrupt:\n",
    "        print(\"Exit\")  # Exit on CTRL+C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "243f457c-34fb-4a0a-91a9-259719f6e84a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
